package vg.interfaces.ll_services.data_base_service.data.graph;

import java.util.ArrayList;
import java.util.List;

/**
 * This class realizes edge between vertexes.
 * Warning: No thread safety.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public class Edge extends AttributeItem implements Cloneable {
	// Main data
	private Vertex source = null;
	private Vertex target = null;
	
//=============================================================================
//-----------------Constructors------------------------------------------------
	public Edge() {
		this(null, null);
	}
	
	public Edge(Vertex source, Vertex target) {
		this(source, target, new ArrayList<Attribute>());

	}
	
	public Edge(Vertex source, Vertex target, List<Attribute> attributes) {
		super(attributes);
		this.source = source;
		this.target = target;
	}
	
	public Edge(Vertex source, Vertex target, AttributeItem item) {
		super(item);
		this.source = source;
		this.target = target;
	}	
	
//=============================================================================
//-----------------PUBLIC METHODS----------------------------------------------
	public Vertex getSource() {
		return source;
	}

	public Vertex getTarget() {
		return target;
	}
	
	public void setSource(Vertex source) {
		this.source = source;
	}
	
	public void setTarget(Vertex target) {
		this.target = target;
	}
	
	public void setNodes(Vertex source, Vertex target) {
		this.source = source;
		this.target = target;
	}
	
	@Override
	public Edge clone() {
		return new Edge(source.clone(), target.clone(), super.clone());
	}
	
	@Override
	public int hashCode() {
		return getStorableId();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this) return true;
		
		if (obj instanceof Edge) {
			if (getStorableId() >= 0 && getStorableId() == ((Edge)obj).getStorableId())
				return true;
		}		
		return false;
	}
}
